<script setup>
// import router from "@/router";
import {computed, defineProps, defineEmits, onMounted, watch} from "vue";
import {useRoute} from "vue-router";
import store from "@/store";

const prop = defineProps({
  open_btn: {
    default: () => false,
    type: Boolean
  }
})
const emit = defineEmits(['menuHideShow'])
const hideMenuBtn = computed(() => {
  return prop.open_btn ? "Expand" : "Fold"
})
const route = useRoute()
const account = computed(() => store.state.account)
watch(route, (to) => {
  if (to.name !== 'login') store.dispatch("getUser")
})
onMounted(() => {
  if (route.name !== 'login') {
    store.dispatch("getUser")
  }
})
const handleCommand = (command) => {
  console.log(command)
}
</script>

<template>
  <div class="vea-header">
    <div class="vea-title">
      <div>智行九州管理系统</div>
    </div>
    <div class="vea-nav">
      <div>
        <el-button :icon="hideMenuBtn" size="small" plain @click="emit('menuHideShow')"/>
      </div>
      <div class="right-menu">
        <el-dropdown @command="handleCommand" class="vea-menu">
          <div class="vea-menu-title">
            <el-avatar src="/img/icons/admin5.png" fit="cover"></el-avatar>
            <span style="padding-left: 10px">
<!--              {{ userInfo.surname || userInfo.username }}-->
              {{ account.account }}
            </span>
            <el-icon>
              <CaretBottom/>
            </el-icon>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="modify" icon="edit">
                修改密码
              </el-dropdown-item>
              <el-dropdown-item command="down" icon="download">
                下载中心
              </el-dropdown-item>
              <el-dropdown-item command="logout" icon="switch-button">
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.vea-header {
  height: 45px;
  background: var(--default-color);
  display: flex;
  align-items: center;
  //justify-content: space-between;
  box-sizing: border-box;

  .vea-title {
    box-sizing: border-box;
    padding: 10px;
    background: rgba(255, 255, 2255, .6);
    height: 100%;
    color: #ffffff;
    width: 220px;
    display: flex;
    //font-size: .8rem;
    align-items: center;
    justify-content: center;

    &.mobile-title {
      width: 100px;
    }

    .el-image {
      height: 100%;
    }
  }

  .vea-nav {
    display: flex;
    justify-content: space-between;
    width: calc(100% - 225px);
    margin-left: 5px;
    align-items: center;

    &.mobile-nav {
      width: calc(100% - 105px);
    }

    .vea-menu {
      padding: 10px;
      color: #fff;

      .vea-menu-title {
        display: flex;
        align-items: center;
      }
    }
  }

  .right-menu {
    display: flex;
    align-items: center;
    //color: #ffffff;

    .search-menu {
      display: flex;
      align-items: center;
      background: #ffffff;
      padding: 5px 20px;
      border-radius: 5px;
      color: var(--el-color-info);
      cursor: pointer;

      .el-icon {
        margin-right: 10px;
      }
    }
  }
}

</style>
